/* GUI CONVERTED from rcschdla.p (converter v1.76) Mon Aug  5 00:32:01 2002 */
/* rcschdla.p - Release Management Customer Schedules                         */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.13 $                                                          */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.3      LAST MODIFIED: 08/13/93   BY: WUG *GE19*                */
/* REVISION: 8.6      LAST MODIFIED: 09/20/96   BY: TSI *K005*                */
/* REVISION: 8.6      LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 9.0      LAST MODIFIED: 01/14/99   BY: *M05B* Steve Nugent       */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan         */
/* REVISION: 9.0      LAST MODIFIED: 05/29/00   BY: *L0YB* Santosh Rao        */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* REVISION: 9.1      LAST MODIFIED: 01/03/00   BY: *M0ZN* Rajesh Thomas      */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.13 $       BY: Vandna Rohira    DATE: 08/04/02  ECO: *N1Q2*   */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* SCHEDULE DELETE SUBPROGRAM */

/* INCLUDE FILE CONTAINING DEFINITION OF SHARED VARIABLES */
{mfdeclre.i}

/* INPUT PARAMETER DEFINITIONS */
define input parameter schtype     like sch_type.
define input parameter schnbr      like sch_nbr.
define input parameter schline     like sch_line.
define input parameter schrlseid   like sch_rlse_id.
define input parameter detail_only like mfc_logical.

/* LOCAL VARIABLE DEFINITIONS */
define variable schdtype      like schd_type      no-undo.
define variable schdnbr       like schd_nbr       no-undo.
define variable schdline      like schd_line      no-undo.
define variable schdrlseid    like schd_rlse_id   no-undo.
define variable schddate      like schd_date      no-undo.
define variable schdtime      like schd_time      no-undo.
define variable schdinterval  like schd_interval  no-undo.
define variable schdreference like schd_reference no-undo.
define variable errgen        as   logical        no-undo.
define variable l_cum_qty     like schd_cum_qty   no-undo.
define variable l_pcs_date    like sch_pcs_date   no-undo.

find sch_mstr
   where sch_type    = schtype
   and   sch_nbr     = schnbr
   and   sch_line    = schline
   and   sch_rlse_id = schrlseid
   exclusive-lock no-error.

if not available sch_mstr
then
   leave.

for each schd_det
   where schd_type    = sch_type
   and   schd_nbr     = sch_nbr
   and   schd_line    = sch_line
   and   schd_rlse_id = sch_rlse_id
   exclusive-lock:
/*GUI*/ if global-beam-me-up then undo, leave.


   for each cmt_det
      where cmt_indx = schd_cmtindx
      exclusive-lock:

      delete cmt_det.

   end. /* FOR EACH cmt_det */

   assign
      schdtype      = schd_type
      schdnbr       = schd_nbr
      schdline      = schd_line
      schdrlseid    = schd_rlse_id
      schddate      = schd_date
      schdtime      = schd_time
      schdinterval  =  ""
      schdreference = schd_reference.

   /* RELEASE MANAGEMENT CUSTOMER SCHEDULES */
   {gprun.i ""rcscmtc.p""
      "(input  recid(schd_det),
        output errgen)"}
/*GUI*/ if global-beam-me-up then undo, leave.


   if errgen
   then
      undo, return.

   /* RELEASE MANAGEMENT CUSTOMER SCHEDULES */
   {gprun.i ""rcrqmdel.p""
      "(input recid(schd_det))"}
/*GUI*/ if global-beam-me-up then undo, leave.


   delete schd_det.

   if schdtype    = 5
      or schdtype = 6
   then do:

      assign
         l_cum_qty   = sch_pcr_qty
         l_pcs_date  = sch_pcs_date.

      /* INTERNAL PROCEDURE TO DELETE TYPE 4 DETAIL */
      run delete_type_4_det
        (input schdnbr,
         input schdline,
         input schdrlseid,
         input schddate,
         input schdtime,
         input schdinterval,
         input schdreference).

   end. /* IF schdtype = 5 */

end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* FOR EACH schd_det */

if not detail_only
then do:

   for each cmt_det
      where cmt_indx = sch_cmtindx
      exclusive-lock:

      delete cmt_det.

   end. /* FOR EACH cmt_det */

   delete sch_mstr.

   if schtype    = 5
      or schtype = 6
   then
      /* INTERNAL PROCEDURE TO DELETE TYPE 4 HEADER/MASTER RECORD */
      run delete_type_4_mstr
        (input schtype,
         input schnbr,
         input schline,
         input schrlseid).

end. /* IF NOT detail_only */


PROCEDURE delete_type_4_det:

   /* INTERNAL PROCEDURE TO DELETE TYPE 4 DETAIL */

   /* INPUT PARAMETER DEFINITIONS */
   define input parameter nbr       like schd_nbr       no-undo.
   define input parameter line      like schd_line      no-undo.
   define input parameter rlse_id   like schd_rlse_id   no-undo.
   define input parameter date      like schd_date      no-undo.
   define input parameter p_time    like schd_time      no-undo.
   define input parameter interval  like schd_interval  no-undo.
   define input parameter reference like schd_reference no-undo.

   /* LOCAL VARIABLE DEFINITIONS */
   define variable        schtype   like schd_type
                                    initial 4           no-undo.
   /* BUFFER DEFINITIONS */
   define buffer type4_sch_mstr for sch_mstr.

   for each schd_det
      where schd_type      = schtype
      and   schd_nbr       = nbr
      and   schd_line      = line
      and   schd_rlse_id   = rlse_id
      and   schd_date      = date
      and   schd_time      = p_time
      and   schd_interval  = interval
      and   schd_reference = reference
      exclusive-lock:

      for each cmt_det
         where cmt_indx = schd_cmtindx
         exclusive-lock:

         delete cmt_det.

      end. /* FOR EACH cmt_det */

      delete schd_det.

   end. /* FOR EACH schd_det */

   for first type4_sch_mstr
      where type4_sch_mstr.sch_type    = 4
      and   type4_sch_mstr.sch_nbr     = nbr
      and   type4_sch_mstr.sch_line    = line
      and   type4_sch_mstr.sch_rlse_id = rlse_id
      exclusive-lock:

      assign
         type4_sch_mstr.sch_pcr_qty  = l_cum_qty
         type4_sch_mstr.sch_pcs_date = l_pcs_date.

   end. /* FOR FIRST type4_sch_mstr */

   for each schd_det
      where schd_type    = schtype
      and   schd_nbr     = nbr
      and   schd_line    = line
      and   schd_rlse_id = rlse_id
      exclusive-lock:

      assign
         schd_fc_qual = (if schd_fc_qual = "F"
                         then
                            "P"
                         else
                            schd_fc_qual)
         schd_upd_qty = schd_discr_qty
         l_cum_qty    = l_cum_qty + schd_discr_qty
         schd_cum_qty = l_cum_qty.

   end. /* FOR EACH schd_det */

END PROCEDURE. /* PROCEDURE delete_type_4_det */


PROCEDURE delete_type_4_mstr:

   /* INTERNAL PROCEDURE TO DELETE TYPE 4 HEADER/MASTER RECORD */

   /* INPUT PARAMETER DEFINITIONS */
   define input parameter type    like sch_type    no-undo.
   define input parameter nbr     like sch_nbr     no-undo.
   define input parameter line    like sch_line    no-undo.
   define input parameter rlse_id like sch_rlse_id no-undo.

   /* LOCAL VARIABLE DEFINITIONS */
   define variable        p_type  like sch_type    no-undo.

   /* BUFFER DEFINITIONS */
   define buffer b_sch_mstr1 for sch_mstr.
   define buffer b_sch_mstr2 for sch_mstr.

   if type = 5
   then
      p_type = 6.
   else
      p_type = 5.

   /* IF DELETING A PLANNING SCHEDULE THEN CHECK FOR A SHIPPING    */
   /* SCHEDULE. IF DELETE A SHIPPING SCHEDULE CHECK FOR A PLANNING */
   /* SCHEDULE. IF ONE IS FOUND THEN WE DO NOT WANT TO DELETE      */
   /* THE TYPE 4 SCHEDULE MASTER BECAUSE WHICH EVER SCHEDULE IS    */
   /* STILL IN EXISTENCE WILL NEED THE TYPE 4 MASTER. IF THE       */
   /* SCHEDULE WE ARE DELETING DOES NOT HAVE A PLANNING/SHIPPING   */
   /* COUNTERPART THEN WE WILL DELETE THE TYPE 4 MASTER.           */

   if (can-find(first b_sch_mstr1
                where b_sch_mstr1.sch_type    = p_type
                and   b_sch_mstr1.sch_nbr     = nbr
                and   b_sch_mstr1.sch_line    = line
                and   b_sch_mstr1.sch_rlse_id = rlse_id
                no-lock))
   then
      return.
   else
      for first b_sch_mstr2
         where b_sch_mstr2.sch_type    = 4
         and   b_sch_mstr2.sch_nbr     = nbr
         and   b_sch_mstr2.sch_line    = line
         and   b_sch_mstr2.sch_rlse_id = rlse_id
         exclusive-lock:

         delete b_sch_mstr2.

      end. /* FOR FIRST b_sch_mstr2 */

END PROCEDURE.  /* PROCEDURE delete_type_4_mstr */
